#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

//打印数组
template<class T>
void PrintVec(const std::vector<T>& vec) {
    for (int i = 0; i < vec.size(); i++) {
        std::cout << vec[i] << " ";
    }
    std::cout << "\n";
}


//尾插
void Test01() {
    std::vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    vec.push_back(3);

    PrintVec(vec);
}

//改
void Test02() {
    std::vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    vec.push_back(3);

    vec[2] = 777;
    PrintVec(vec);
}

//随机插入
void Test03() {
    std::vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    vec.push_back(3);

    vec.insert(vec.begin() + 3, 999);

    PrintVec(vec);
}

//实现push_front
void Test04() {
    int arr[] = { 1, 2, 3, 4 };

    std::vector<int> vec;

    for (int i = 0; i < 4; i++) {
        vec.insert(vec.begin(), arr[i]);
    }

    //期望是4 3 2 1
    PrintVec(vec);

}

//排序
void Test05() {
    std::vector vec = { 4,7,1,4,6 };

    std::sort(vec.begin(), vec.end());

    PrintVec(vec);
}


//部分排序
void Test06() {
    std::vector vec = { 4,7,1,4,6 };

    std::sort(vec.begin(), vec.begin() + 3);

    PrintVec(vec);
}


struct Student {
    std::string name;
    int age;
};

std::ostream& operator<<(std::ostream& os, const Student& s) {
	os << "{" << s.name << "," << s.age << "}";
	return os;
}

//存放struct
void Test07() {
    std::vector<Student> classes;

    Student s1 = { "zhangsan", 20 };
    classes.push_back(s1);

    PrintVec(classes);
}

//默认值
void Test08() {
    std::vector<int> vec(10, 555);

	PrintVec(vec);
}

//删除
void Test09() {
    std::vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    vec.push_back(3);

    std::vector<int>::iterator iterator = vec.erase(vec.begin() + 1);
	PrintVec(vec);
    //删掉的是2，返回的是指向3的迭代器
    std::cout << *iterator << "\n";

}

/**
 * 数组的基本用法
 *
 */
int main() {
     Test01();
    // Test02();

    // Test03();

    // Test04();

    //Test05();

    // Test06();

    //Test07();

    //Test08();

    // Test09();

    return 0;

}